package com.kingviker.example.zerocopy;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.Socket;

public class OldClient {
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("localhost", 8899);
        String fileName = "F:/1.mp4";
        InputStream inputstream = new FileInputStream(fileName);

        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        byte[] bytes = new byte[4096];
        long readCount = 0;
        long total = 0;
        long startTime = System.currentTimeMillis();
        while((readCount = inputstream.read(bytes))>=0){
            total+=readCount;
            dataOutputStream.write(bytes);
        }
        System.out.println("发送的总字节数:"+total+",耗时:"+(System.currentTimeMillis()-startTime));
        dataOutputStream.close();
        socket.close();
        inputstream.close();
    }
}
